<template>
  <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
            :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
            :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
            :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
    <a-form ref="formRef" :model="formState" layout="vertical" :rules="EXCHANGE_EDIT.RULES">

      <a-form-item label="使用方式" field="kind">
        <smart-dict  v-model="formState.kind"  :is-radio="true" :url="DictOptions.ExchangeKind"/>
      </a-form-item >
      <div v-if="formState.kind === 'PIG'" >

        <a-form-item label="猪猪商品" field="pigGoodsCode">
          <smart-dict v-model="formState.pigGoodsCode" :url="ProductOptions.PigGoodsOptions" placeholder="请填写猪猪商品"/>
        </a-form-item>

        <a-form-item label="包含饲料(月)" field="months">
          <a-input-number v-model="formState.months" mode="button" min="0" placeholder="请填写猪猪数量"/>
        </a-form-item>


      </div>

      <a-form-item v-else label="数量/比例" field="proportion">
        <a-input v-model="formState.proportion" allow-clear placeholder="请填写数量/比例"/>
      </a-form-item>

      <a-form-item label="生成数量" field="number">
        <a-input v-model="formState.number" allow-clear placeholder="请填写生成数量"/>
      </a-form-item>

    </a-form>

  </a-drawer>
</template>

<script lang="ts" setup>


import {EditDrawer} from '@/libs/core'
import {EXCHANGE_EDIT} from "../../cdk/resource/form";
import {PopBasicHttp} from '../../cdk/resource/http'
import {DictOptions, ProductOptions} from "@/libs/options";


const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])

const {addExchange, updateExchange} = PopBasicHttp
const config = {tplRecord: EXCHANGE_EDIT.BODY, rawRecord: props.record, rowKey: 'id', emit}


const service = new EditDrawer(config).setAddRequest(addExchange).setUpdateRequest(updateExchange)
const {formRef, formState, LAYER, onCancel, onSubmit} = service
LAYER.title = '生成兑换码'
</script>
